package com.lianxian.xindong.old.fragment.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.lianxian.xindong.old.R;
import com.lianxian.xindong.old.fragment.home.selffile.adapter.MainAdapter;
import com.lianxian.xindong.old.fragment.home.selffile.adapter.utils.VideoPlayRecyclerView;
import com.lianxian.xindong.old.fragment.home.selffile.entities.VideoData;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link SelfieFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class SelfieFragment extends Fragment {

    private VideoPlayRecyclerView mRvVideo;
    private MainAdapter adapter;
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public SelfieFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment SelfieFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static SelfieFragment newInstance(String param1, String param2) {
        SelfieFragment fragment = new SelfieFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View root= inflater.inflate(R.layout.fragment_selfie, container, false);
        mRvVideo = root.findViewById(R.id.rvVideo);
        adapter = new MainAdapter(getActivity(),getVideoInfos());
        mRvVideo.setAdapter(adapter);
        return root;
    }
    List<VideoData> getVideoInfos(){
        List<VideoData> list = new ArrayList<>();
        VideoData videoData = new VideoData();
        videoData.setPicUrl("https://tx2.a.yximgs.com/upic/2020/04/24/20/BMjAyMDA0MjQyMDExMDRfNTkzMzMzMzJfMjczMzU3NDA0ODVfMV8z_B26385cd47079260e711ba54cdf65b594.jpg");
        videoData.setVideoUrl("https://txmov2.a.yximgs.com/bs2/newWatermark/MjczMzU3NDA0ODU_zh_3.mp4");
        list.add(videoData);
        videoData = new VideoData();
        videoData.setVideoUrl("https://vd4.bdstatic.com/mda-pf83dxdpe3m61ep6/sc/cae_h264/1686465290409357292/mda-pf83dxdpe3m61ep6.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1687343551-0-0-def6402ff3f70f63fa0a4bc3998047eb&bcevod_channel=searchbox_feed&cd=0&pd=1&pt=3&logid=0151687576&vid=17637307374472944902&abtest=110930_1&klogid=0151687576");
        list.add(videoData);
        return list;
    }

    @Override
    public void onPause() {
        super.onPause();
        adapter.pause();
    }

    @Override
    public void onResume() {
        super.onResume();
        adapter.resume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        adapter.release();
    }
}